/**   
 * @Title: AgainstTeamListLocalFilter.java 
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact.sportteryfootballapg 
 * @Description: (对阵列表本地筛选) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-9-5 上午11:42:12  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.cheetah.view.personal.sportlotteryfootball;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;

import android.util.Log;

import com.esun.cheetah.view.personal.sportlotteryfootballinfo.SportteryFootballAgainstInfo;

/**
 * 
 * @Package com.esun.cheetah.view.personal.sportlotteryfootball.AgainstTeamListLocalFilter
 * @ClassName: AgainstTeamListLocalFilter
 * @Description: TODO(Against team list )
 * @author handy <br/>
 * @date create at 2012-7-31 下午2:44:45
 *
 */
public class AgainstTeamListLocalFilter {
	private ArrayList<Hashtable<String, Object>> list;
	private int rangqiuType;
	private int peilvType;
	private HashSet<String> leagueNameList;

	private static final String IS_TITLE = "is_title";
	private static final String INFO = "info";
	private static final String IS_ACTIVE = "is_active";
	private static final String IS_SHOW = "is_show";
	private static final String W = "w";
	private static final String D = "d";
	private static final String L = "l";
	private static final String IS_DAN = "is_dan";

	public AgainstTeamListLocalFilter(ArrayList<Hashtable<String, Object>> list) {
		this.list = list;
	}

	public ArrayList<Hashtable<String, Object>> getResult(int rangqiuType,
			HashSet<String> leagueNameList) {
		this.rangqiuType = rangqiuType;
		this.leagueNameList = leagueNameList;
		for (int i = 0; i < list.size(); i++) {
			if ((Boolean) list.get(i).get(IS_TITLE)) {
				list.get(i).put(IS_SHOW, true);
			} else if (isRightLeague((SportteryFootballAgainstInfo) list.get(i)
					.get(INFO))
					&& isRightRangqiu((SportteryFootballAgainstInfo) list
							.get(i).get(INFO))) {
				list.get(i).put(IS_SHOW, true);
			} else {
				list.get(i).put(IS_SHOW, false);
				list.get(i).put(IS_ACTIVE, false);
				list.get(i).put(W, false);
				list.get(i).put(D, false);
				list.get(i).put(L, false);
				list.get(i).put(IS_DAN, false);
			}
		}
		return list;
	}

	// 0:全部,1:让球,2:非让球
	private boolean isRightRangqiu(
			SportteryFootballAgainstInfo sportteryFootballAgainstInfo) {
		boolean b = false;
		if (rangqiuType == 0) {
			b = true;
		} else if (rangqiuType == 1) {
			if (sportteryFootballAgainstInfo.getRangqiu().equals("0")) {
				b = false;
			} else {
				b = true;
			}
		} else if (rangqiuType == 2) {
			if (sportteryFootballAgainstInfo.getRangqiu().equals("0")) {
				b = true;
			} else {
				b = false;
			}
		} else {
			b = false;
		}
		return b;
	}

	/** 0:全部,1:高命中区间,2:实力赔率区间,3:高额回报区间 */
	@SuppressWarnings("unused")
	private boolean isRightPeilv(SportteryFootballAgainstInfo sportteryFootballAgainstInfo) {
		boolean b = false;
		double w = Double.parseDouble(sportteryFootballAgainstInfo.getWin());
		double d = Double.parseDouble(sportteryFootballAgainstInfo.getDraw());
		double l = Double.parseDouble(sportteryFootballAgainstInfo.getLost());
		if (peilvType == 0) {
			b = true;
		} else if (peilvType == 1) {
			if (w < 1.5) {
				b = true;
			} else if (d < 1.5) {
				b = true;
			} else if (l < 1.5) {
				b = true;
			} else {
				b = false;
			}
		} else if (peilvType == 2) {
			if (w >= 1.5 && d < 2) {
				b = true;
			} else if (d >= 1.5 && d < 2) {
				b = true;
			} else if (l >= 1.5 && d < 2) {
				b = true;
			} else {
				b = false;
			}

		} else if (peilvType == 3) {
			if (w >= 2) {
				b = true;
			} else if (d >= 2) {
				b = true;
			} else if (l >= 2) {
				b = true;
			} else {
				b = false;
			}

		} else {
			b = false;
		}
		return b;
	}

	//
	private boolean isRightLeague(
			SportteryFootballAgainstInfo sportteryFootballAgainstInfo) {
		boolean b = false;

		String strItmeLeague = sportteryFootballAgainstInfo.getSimpleleague();

		Log.e("Filter", strItmeLeague + " --->  " + leagueNameList);

		if (leagueNameList.contains(strItmeLeague)) {
			b = true;
		}

		return b;
	}
}
